package com.example.tmp;

import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Tree基类
 */
@Setter
@Getter
public class TreeEntity<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    private T id;
    private T parentId;

    private TreeEntity<T> parent;
    private List<TreeEntity<T>> children = new ArrayList<>();

    public void setParent(TreeEntity<T> parent) {
        this.parent = parent;
        if (null != parent) {
            this.setParentId(parent.getId());
        }
    }

    public TreeEntity<T> addChild(TreeEntity<T> node) {
        this.children.add(node);
        return this;
    }
}